<template>
  <div class="comment-container">
    <el-card class="box-card">
        <el-row style="margin: 10px">
        <el-col :span="24">
          <el-button
            type="danger"
            size="small"
            icon="el-icon-delete"
            @click="deleteClick"
            >批量删除</el-button
          >
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table
        :data="reportsList"
        style="width: 100%"
        stripe
        lazy
        @selection-change="handleSelectionChange"
        >>
        <el-table-column type="selection" width="50"> </el-table-column>
        <el-table-column prop="article.title" label="被举报文章">  </el-table-column>
         <el-table-column label="举报类型"   align="center">
        <template  v-slot="slot">
        <el-tag size="medium" v-if="slot.row.type == 0">其他问题 </el-tag>
        <el-tag size="medium" v-else-if="slot.row.type == 1">标题夸张</el-tag>
        <el-tag size="medium" v-else-if="slot.row.type == 2">低俗色情</el-tag>
        <el-tag size="medium" v-else-if="slot.row.type == 3">错别字多</el-tag>
        <el-tag size="medium" v-else-if="slot.row.type == 4">旧闻重复</el-tag>
        <el-tag size="medium" v-else-if="slot.row.type == 5">涉嫌广告</el-tag>
        <el-tag size="medium" v-else-if="slot.row.type == 6">内容抄袭</el-tag>
        <el-tag size="medium" v-else-if="slot.row.type == 7">政治相关</el-tag>
        <el-tag size="medium" v-else-if="slot.row.type == 8">内容不实</el-tag>
        <el-tag size="medium" v-else-if="slot.row.type == 9">涉嫌违法犯罪</el-tag>
        <el-tag size="medium" v-else-if="slot.row.type == 10">侵犯名誉/隐私/著作/肖像权等</el-tag>
        </template>
        </el-table-column>
        <el-table-column prop="user.user_name" label="举报人" width="80" align="center"> </el-table-column>
        <el-table-column prop="remark" label="举报描述" > </el-table-column>
         <el-table-column prop="stutas" label="处理状态" >
          <template  v-slot="slot">
           <!-- 0:审核失败;1:审核中;2:审核完成,内容未违规,3:审核完成,内容违规已删除该文章 -->
        <p v-if="slot.row.status == 0">审核失败</p>
        <p v-else-if="slot.row.status == 1">审核中 </p>
        <p v-else-if="slot.row.status == 2">审核完成,内容未违规 </p>
        <p v-else-if="slot.row.status == 3">审核完成,内容违规已删除该文章 </p>
        </template>
        </el-table-column>
         <el-table-column
          prop="createdAt"
          label="举报时间"
          width="160"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="address" label="操作" width="180" align="center">
          <template v-slot="slot">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              @click="auditClick(slot.row)"
              >审核</el-button
            >
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="small"
              @click="deleteClick(slot.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="queryInfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 审核对话框 -->
    <el-dialog
  title="审核举报"
  :visible.sync="auditDialogVisible"
  width="30%"
   center
  :before-close="handleClose">
  <el-radio-group v-model="radio">
    <el-radio :label="1">审核中</el-radio>
    <el-radio :label="2">审核完成,内容未违规</el-radio>
    <el-radio :label="3">审核完成,内容违规已删除该文章</el-radio>
  </el-radio-group>
  <span slot="footer" class="dialog-footer">
    <el-button @click="auditDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="auditOk">确 定</el-button>
  </span>
</el-dialog>
  </div>
</template>

<script>
import { getAccusationArticleList,deleteAccusationArticle,getAccusationArticleInfo,putAccusationArticleInfo} from "@/api/article";
export default {
  name: "Reports",
  data() {
    return {
      reportsList: [], // 文章表格数据
      queryInfo: {
        query: "", // 查询参数
        pageNum: 1, // 分页页码
        pageSize: 10, // 页面数据条数
      },
      total: 0,
      selectRows: [], // 全选数据
      auditDialogVisible: false,
      radio:1,
      rows:{} //获取举报的详细信息
    };
  },
  created() {
    this.getAccusationArticleList();
  },
  methods: {
   async auditOk(){
     const id =  this.rows.id
     const body =  this.radio
      await putAccusationArticleInfo(id,{ status: body})
       this.auditDialogVisible = !this.auditDialogVisible
       this.getAccusationArticleList();
      const res = await getAccusationArticleInfo(id)
      switch (res.status) {
		case 1:
			this.$message.info('审核状态为：审核中')
		break
		case 2:
			this.$message.success('审核完成,内容未违规')
		break
	  case 3:
			this.$message.warning('审核完成,内容违规已删除该文章')
		break
	}
    },

    handleClose(done){
       done();
    },
    // 数据
    async getAccusationArticleList() {
      const { list, pageNum, pageSize, total } = await getAccusationArticleList(
        this.queryInfo
      );
      this.reportsList = list;
      this.queryInfo.pageNum =Number(pageNum);
      this.queryInfo.pageSize =Number(pageSize);
      this.total = total;
    },
    // 设置页面数据条数
    handleSizeChange(val) {
      this.queryInfo.pageSize = val;
      this.getAccusationArticleList();
    },
    // 设置分页页码
    handleCurrentChange(val) {
      this.queryInfo.pageNum = val;
      this.getAccusationArticleList();
    },
    // 点击审核
   async auditClick(row) {
     const res = await getAccusationArticleInfo(row.id)
     this.radio = res.status
     this.rows = res
      this.auditDialogVisible = !this.auditDialogVisible
    },
    // 删除
    deleteClick(row) {
       if (row.id) {
        this.$confirm("你确定要删除选中项吗", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(async () => {
            await deleteAccusationArticle({ ids: [row.id] });
            this.getAccusationArticleList();
            this.$message.success("删除成功");
          })
          .catch(() => {
            this.$message.info("已取消删除");
          });
      } else {
        // 批量删除
        if (!this.selectRows.length)
          return this.$message.warning("请选择要删除的选中项");
        const ids = this.selectRows.map((item) => item.id);
        this.$confirm("你确定要删除选中项吗", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(async () => {
            await deleteAccusationArticle({ ids });
            this.getAccusationArticleList();
            this.$message.success("删除成功");
          })
          .catch(() => {
            this.$message.info("已取消删除");
          });
      }
    },
    // 全选数据
    handleSelectionChange(val) {
        this.selectRows = val;
    },
  },
};
</script>

<style lang="scss">
// .el-select .el-input {
//   width: 80px;
// }
.el-radio{
    line-height:40px;
  }
.box-card {
  margin: 20px;
}
.el-table {
  margin: 20px 0px;
}
// .el-image {
//   border-radius: 5px;
// }
</style>
